import { useState,useEffect } from 'react'
import { Button } from "antd"

export default function StateHook(props) {
    let [sum,setSum] = useState(props.count)
    useEffect(() => {
        document.title = `${props.count}`
        return () => {
            // 第一次进入/离开
            document.title = '丨小小风离丨'
        }
    },[props.count])
    useEffect(() => {
        setSum(sum)
    },[sum])
    // sum 更新时执行
    return (
        <div>
            <h1>{ props.count }</h1>
            <h2>更新时执行{sum}</h2>
            <Button onClick={props.setCount}>上层</Button>
            <Button onClick={() => {setSum(++sum)}} style={{ marginLeft: 15 }}>更新</Button>
        </div>
    )
}
